/*
	types.h

	defines commonly used data types and functions for 64 bit

	Author: Aidan Goddard 23/4/13
*/

#ifndef TYPES_H_INCLUDED
#define TYPES_H_INCLUDED

/*
typedef unsigned char uint8_t;
typedef char int8_t;
typedef unsigned short uint16_t;
typedef short int16_t;
typedef unsigned int uint32_t;
typedef int int32_t;
typedef unsigned long long uint64_t;
typedef long long int64_t;
*/

#include<stdint.h>

#define NULL (void*)0

// kernel memory area offsets
#define KOFFSET 0x100000000
#define IDT_KOFFSET 0x100700000
#define SYS_KOFFSET 0x100e00000
#define PCI_KOFFSET 0x104200000

// functions to read and write to ports
static inline void outb(uint16_t port, uint8_t val)
{
	__asm__ __volatile__("outb %0, %1" : : "a"(val), "Nd"(port));
	return;
}

static inline uint8_t inb(uint16_t port)
{
	unsigned char ret;
	__asm__ __volatile__("inb %1, %0" : "=a"(ret) : "Nd"(port));
	return ret;
}

static inline void io_wait()
{
	// port 0x80 is used for 'checkpoints' during POST.
	// The Linux kernel seems to think it is free for use :/
	__asm__ __volatile__("outb %%al, $0x80"::"a"(0));
	return;
}

// functions to read and write to and from MSRs
static inline void cpuGetMSR(uint32_t msr, uint32_t *lo, uint32_t *hi)
{
	__asm__ __volatile__("rdmsr" : "=a"(*lo), "=d"(*hi) : "c"(msr));
	return;
}

static inline void cpuSetMSR(uint32_t msr, uint32_t lo, uint32_t hi)
{
	__asm__ __volatile__("wrmsr" : : "a"(lo), "d"(hi), "c"(msr));
	return;
}

#define outportb outb
#define inportb inb
#define rdmsr cpuGetMSR
#define wrmsr cpuSetMSR

typedef uint64_t HWND;
typedef uint64_t HANDLE;

#endif






